function [] = Tester( ClassName, varargin  )
%TESTER Testowanie klas populacji
%   Tworzy populacjie i przeprawadza testy



load data;

% defaults
PopulationSize = 50;
GenerationsNumber = 200;
StopSize = 'Small';
DataType = 'Normal';

%% Parsowanie argumentow wejsciowych
numArgumetns=length(varargin);
for indArg=1:2:numArgumetns
    switch lower(varargin{indArg})
        case 'populationsize'
            PopulationSize=varargin{indArg+1};
        case 'generationsnumber'
            GenerationsNumber=varargin{indArg+1};
        case 'stopssize'
            StopSize=varargin{indArg+1};
        case 'datatype'
            DataType=varargin{indArg+1};
        otherwise
            error(['Tester >< Unknown parameter ''',varargin{indArg},'''.']) ;
    end
end

%% Dane poczatkowe
data_name = 'data_';

switch lower(DataType)
    case 'normal'
        data_name = strcat(data_name,'normal_');
    case 'rand'
        data_name = strcat(data_name,'rand_');
    case 'bad'
        data_name = strcat(data_name,'bad_');
    case 'bad2'
        data_name = strcat(data_name,'bad2_');
    otherwise
        error(['Tester >< Unknown parameter ''',StopSize,'''.']) ;
        data_name = strcat(data_name,data_type,'_');
end

switch lower(StopSize)
    case 'small'
        data_name = strcat(data_name,'small');
    case 'medium'
        data_name = strcat(data_name,'medium');
    case 'big'
        data_name = strcat(data_name,'big');
    case 'large'
        data_name = strcat(data_name,'large');
    otherwise
        error(['Tester >< Unknown parameter ''',StopSize,'''.']) ;
        data_name = strcat(data_name,StopSize);
end

center_of_cluster = eval(data_name);
%% Przystanki
Stops.getInstance.init(center_of_cluster(:,1:2),generate_distances(center_of_cluster(:,1:2)),center_of_cluster(:,3));


%% Populacja
Population = ClassName( PopulationSize, SimpleIndividual );

%% Pierwsze pokolenie - losowe

Population.compute_objectives
Population.sort();
[he,hv,ht] = Population.best.disp_connections;

%% Zycie
tic;
progress = zeros(1,GenerationsNumber +1);
progress(1) = Population.best.objective_value;
for k=1:GenerationsNumber
    Population.to_next_generation();
    Population.compute_objectives();
    Population.sort();
    progress(k+1) = Population.best.objective_value;
end
toc;


%% Wynik

delete(he);
delete(hv);
delete(ht);
[he,hv,ht] = Population.best.disp_connections;

%% Najlepszy znaleziony
delete(he);
delete(hv);
delete(ht);
Population.best_of_all.disp_connections;


%% Postep
clf;
plot(progress);
end

